<?php
declare (strict_types = 1);

namespace app\command;

use app\api\repository\TakeawayAttachRepository;
use app\model\zs\ZsTwShopDetail;
use think\console\Command;
use think\console\Input;
use think\console\input\Argument;
use think\console\input\Option;
use think\console\Output;

class TakeawayAutoFillCateAndTag extends Command
{
    protected function configure()
    {
        // 指令配置
        $this->setName('tw:fill-cate-tag')
            ->setDescription('批量填充外卖商品的分类和标签');
    }

    protected function execute(Input $input, Output $output)
    {
        $takeawayAttachRepository = app(TakeawayAttachRepository::class);
        $list_shop = ZsTwShopDetail::where('open', ZsTwShopDetail::OPEN_ON)->select();
        foreach ($list_shop as $item_shop) {
            $bid = $item_shop['bid'];
            if (!$takeawayAttachRepository->isExistCate($bid)) {
                $takeawayAttachRepository->autoFillCate($bid);
                $takeawayAttachRepository->autoRenewCate($bid);
            }
            if (!$takeawayAttachRepository->isExistTag($bid)) {
                $takeawayAttachRepository->autoFillTag($bid);
            }
        }

        // 指令输出
        $output->writeln("ok");
        return;
    }
}
